import { defineConfig } from '@umijs/max';
import { currentUrl } from '../src/env/env';
import cdns, { links } from './cdn';
import routes from './routes';
const isProd = process.env.NODE_ENV === 'production';
export default defineConfig({
  antd: {},
  access: {},
  model: {},
  esbuildMinifyIIFE: true,
  initialState: {},
  // mfsu: false,
  externals: {
    react: 'React',
    'react-dom': 'ReactDOM',
    antd: 'antd',
    dayjs: 'dayjs',
  },

  // 去除console
  extraBabelPlugins: [isProd ? 'transform-remove-console' : ''],
  // extraBabelPlugins: [isProd ? [removeLog] : []],
  links: links,
  headScripts: [...cdns, 'https://lib.baomitu.com/antd/5.11.2/antd.min.js'],
  define: {
    'process.env': process.env,
  },
  analyze: {
    analyzerMode: 'server',
    analyzerPort: 8889,
    openAnalyzer: true,
    // generate stats file while ANALYZE_DUMP exist
    generateStatsFile: false,
    statsFilename: 'stats.json',
    logLevel: 'info',
    defaultSizes: 'parsed', // stat  // gzip  // parsed
  },

  codeSplitting: {
    jsStrategy: 'granularChunks',
  },
  publicPath: '/static/',
  hash: true,
  layout: {
    title: '@umijs/max项目',
  },
  request: {},
  proxy: {
    '/api': {
      target: currentUrl,
      changeOrigin: true,
      pathRewrite: { '^/api': '' },
    },
  },
  routes,
  npmClient: 'pnpm',
});
